package MyGO.controller;

import MyGO.Form.TrackForm;
import MyGO.property.CheckPro;
import MyGO.service.ICheackProService;
import MyGO.service.impl.CheckProServiceImpl;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Huanzheluru {

    @FXML
    private TableView<CheckPro> biaoge;

    @FXML
    private Label binglihao;

    @FXML
    private Label name;

    @FXML
    private Label nianling;

    @FXML
    private AnchorPane now;

    @FXML
    private Button sure;

    @FXML
    private Label xingbie;
    private ICheackProService service = new CheckProServiceImpl();

    public void initialize()
    {
        if (Jianchajianchashenqing.getUser()==null){
            Alert alert = new Alert(Alert.AlertType.WARNING);
            alert.setContentText("您未选择患者！");
            now.getChildren().clear();
            alert.showAndWait();
            return;
        }
        //显示患者信息
        name.setText("姓名:"+Jianchajianchashenqing.getUser().getPatientInfoForm().getName());
        nianling.setText("年龄:"+Jianchajianchashenqing.getUser().getPatientInfoForm().getYear());
        xingbie.setText("性别:"+Jianchajianchashenqing.getUser().getPatientInfoForm().getGender());
        binglihao.setText("病历号:"+Jianchajianchashenqing.getUser().getId());

        //导入患者检查项目
        HashMap<String, CheckPro> checkProHashMap = service.getAllCheckPro();
        List<CheckPro> checkProList = new ArrayList<>();
        for (var ChackProID : Jianchajianchashenqing.getUser().getCheckForm().getCheckProIDs()) {
            checkProList.add(checkProHashMap.get(ChackProID));
        }
        ObservableList<CheckPro> data = FXCollections.observableArrayList(checkProList);

        //实现表格
        TableColumn<CheckPro, String> idColumn = new TableColumn<>("检查编号");
        TableColumn<CheckPro, String> nameColumn = new TableColumn<>("检查名称");
        TableColumn<CheckPro, String> specificColumn = new TableColumn<>("检查规格");
        TableColumn<CheckPro, String> priceColumn = new TableColumn<>("价格");


        nameColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getName()));
        specificColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getSpecific()));
        priceColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getPriceStr()));
        idColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getId()));
        biaoge.setItems(data);
        biaoge.getColumns().addAll(idColumn, nameColumn, specificColumn, priceColumn);

        sure.setOnAction(e -> {
            Jianchajianchashenqing.getUser().setStatus_main("检查中");

            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.setContentText("检查完成，请进行下一步操作");
            now.getChildren().clear();
            alert.showAndWait();
        });
    }

}
